package com.zh.eventdispatch.activity;

import android.content.Intent;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * @author wally
 * @date 2021/06/20
 */
public abstract class EventDispatcherActivity extends AppCompatActivity implements ActivityEventOwner {
    /**
     * 事件分发器
     */
    private final ActivityEventDispatcher mActivityEventDispatcher = new ActivityEventDispatcher();

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mActivityEventDispatcher.dispatchOnActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onBackPressed() {
        if (!mActivityEventDispatcher.dispatchOnBackPressed()) {
            super.onBackPressed();
        }
    }

    @Override
    public ActivityEventDispatcher getEventDispatcher() {
        return mActivityEventDispatcher;
    }
}